package com.bitin.adorn.modules.system.api;

import com.bitin.adorn.modules.system.domain.Role;
import com.bitin.adorn.modules.system.service.RoleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Mr.Lu
 * @since 2024/5/30 15:48
 */
@Tag(name = "角色")
@RestController
@RequestMapping("/v1/role")
@AllArgsConstructor
@Slf4j
public class RoleController {

    private final RoleService roleService;

    @Operation(summary = "角色-新增", description = "新增角色")
    @PostMapping("/save")
    public Role save(@RequestBody Role role) {
        return roleService.add(role);
    }

    @Operation(summary = "角色-列表")
    @GetMapping("/list")
    public List<Role> list() {
        return roleService.list();
    }

    @Operation(summary = "角色")
    @GetMapping("/{id}")
    public Role one(@PathVariable("id") Long id) {
        return roleService.findById(id);
    }

    @Operation(summary = "角色-删除")
    @DeleteMapping("/{id}")
    public void remove(@PathVariable("id") Long id) {
        roleService.deleteById(id);
    }

    @Operation(summary = "角色-绑定")
    @PostMapping("/bind")
    public Role bind(@RequestParam("id") Long id, @RequestParam("userId") Long userId) {
        return roleService.bind(id, userId);
    }
}
